/**
 * Created by chaiqing on 2017/5/25.
 */
(function ($) {
    var HOME = function () {
        return this;
    };
    HOME.prototype = {
        init: function () {
            this.pageInit();
            this.bindEvent();
        },
        pageInit: function () {

            if (AXCOMMON.browserEnv.isInApp()) {
                //分享
                var share = {
                    key: 'share',
                    title: 'title',
                    content: 'content',
                    link: 'link',
                    img: 'img'
                }
                var hotline = {key: 'hotline'}
                var ocr = {key: 'ocr', type: 'bankCard'}
                AXCOMMON.AnswernApp.navButtons([share, hotline, ocr]);//右上角三个按钮
                // $("#app-header").load("../../html/common/Header.html", function () {
                //     $("#app-header .title").text("app测试");
                // });

            }

        },
        bindEvent: function () {
            var _this = this;
                $("#showShare").on("click", function () {
                    var share = {
                        key: 'share',
                        title: $("title").html(),
                        desc: '这里还不知道说点啥',
                        link: location.href,
                        imgUrl: 'img'
                    }
                    AXCOMMON.AnswernApp.share(share);

                    Jockey.off('share');
                    Jockey.on("share", function (payload) {
                        alert(JSON.stringify(payload));
                    });

                });

                 $(".showShare").on("click", function () {
                    var share = {
                        key: 'share',
                        title: $("title").html(),
                        desc: '这里还不知道说点啥',
                        link: location.href,
                        imgUrl: 'img'
                    }
                    AXCOMMON.AnswernApp.share(share);

                     Jockey.off('share');
                    Jockey.on("share", function (payload) {
                        alert(JSON.stringify(payload));
                    });

                });

                $("#showOcr").on("click", function () {
                    AXCOMMON.AnswernApp.ocr();
                    Jockey.off('ocr');
                    Jockey.on("ocr", function (payload) {
                        alert(JSON.stringify(payload));
                    });
                });

                $("#showLogin").on("click", function () {
                    AXCOMMON.AnswernApp.login();
                    Jockey.off('login');
                    Jockey.on("login", function (payload) {
                        alert(JSON.stringify(payload));
                    });
                });

                $("#getPostion").on("click", function () {
                    AXCOMMON.AnswernApp.location();
                    Jockey.off('location');
                    Jockey.on("location", function (payload) {
                        alert(JSON.stringify(payload));
                    });
                });

                $("#toNativePage").on("click", function () {
                    AXCOMMON.AnswernApp.toNativePage('answern://o.c?a=url&url=http%3a%2f%2fbaidu.com');
                });

                $("#openImage").on("click", function () {
					
                    AXCOMMON.AnswernApp.image();
                    Jockey.off('image');
                    Jockey.on("image", function (payload) {
                        $(".openimg").attr("src", payload.data);
                    });
                });

                $("#openwxAuth").on("click", function () {
                    AXCOMMON.AnswernApp.wxAuth();
                    Jockey.off('wxAuth');
                    Jockey.on("wxAuth", function (payload) {
                        alert(JSON.stringify(payload));
                    });
                });

                $("#opencookie").on("click", function () {
                    alert($.cookie("token"));
                });

        }

    }
    ;
    var home = new HOME();
    home.init();
})(jQuery);
